# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
import scrapy
from itemadapter import ItemAdapter
from scrapy.pipelines.images import ImagesPipeline


class ImgPipeline(ImagesPipeline):
    def get_media_requests(self, item, info):
        # 获取图片url
        url = item['src']
        yield scrapy.Request(url=url)

    def file_path(self, request, response=None, info=None, *, item=None):
        # 获取文件名
        file_name = item['src'].split('/')[-1]
        return file_name

    def item_completed(self, results, item, info):
        return item


class BianpicPipeline:
    def process_item(self, item, spider):
        return item
